/**
 * @class yijs.autoload
 * @fileOverview 自动运行的js配置
 * @author 谢文浩
 * @email mohaiguyan12@126.com
 * @date 2010-01-26
 * Copyright (c) 2010-2010 谢文浩
 */
yijs = yijs || {};
yijs.path = "/lib/yijs/";
yijs.autoload = ['test','air.Db']
function IncludeJS(sId, fileUrl, source) { 
    if ( ( source != null ) && ( !document.getElementById( sId ) ) ){ 
        var oHead = document.getElementsByTagName('HEAD').item(0); 
        var oScript = document.createElement( "script" ); 
        oScript.language = "javascript"; 
        oScript.type = "text/javascript"; 
        oScript.id = sId; 
        oScript.defer = true; 
        oScript.text = source; 
        oHead.appendChild( oScript ); 
    } 

} 
yijs.runAutoload = function(){
	if(yijs.path){
		var _autoload = yijs.autoload;
		var jsSuffix = ".js";
		var _len = _autoload.length;
		function _run(index){
			var url = yijs.path + _autoload[index].replace(/\./g,"/")+jsSuffix;
			if(index < _len){
				$.ajax({
					 type: "GET",
					 url : url,
					 dataType: "text",
					 success : function(data){
					 		IncludeJS(_autoload[index],url,data);
							if(index == _len-1){
								yijs.ready != null && typeof yijs.ready == "function" && yijs.ready.call(this);
							}
							 index ++;
						 	 _run(index);					 	
					 }
	
				})							
			}
		}
		if(_len > 0){
			_run(0);
		}				
	}else{
		alert("请先配置yijs.path！");
	}
}
//开始加载js
yijs.runAutoload();